﻿@page "/"

@using BlazorAdmin.Models
@using BootstrapBlazor.Components
@using Pangeo.Admin.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@{
    Layout = "_Layout";

    var userAgent = HttpContext.Request.Headers["User-Agent"].ToString();

    var userIP = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
    var headers = HttpContext.Request.Headers;
    if (headers.ContainsKey("X-Forwarded-For")) //先判断是否使存在代理信息
        userIP = headers["X-Forwarded-For"].ToString().Split(",", StringSplitOptions.RemoveEmptyEntries)[0]; //用逗号分隔，取第一个地址，防止多级代理取错
    else if (headers.ContainsKey("X-Real-IP")) //代理信息没有设置，则直接获取X-Real-IP
        userIP = headers["X-Real-IP"].ToString();

    var client = new ClientInfo() { Ip = userIP, UserAgent = userAgent };
}

<component type="typeof(App)" render-mode="ServerPrerendered" param-ClientInfo="client"/>